language: python
python: "3.9"
branches:
  only:
  - /^release-.*$/
#  - master
#  - develop

stages:
  - env-test-build-publish

jobs:
  include:
    - stage: env-test-build-publish
      name: "Stages: PRE-BUILDING -> TESTING -> BUILDING -> PUBLISHING to PyPI"
      install:
        - echo "---> Running PRE-BUILDING stage..."
        - python -m pip install --upgrade pip --force-reinstall
        - pip install setuptools==59.5.0 --force-reinstall
        - pip install urllib3==1.26.6 --force-reinstall
        - pip install -r requirements.txt
      before_script:
        - export PYTHONPATH=$PYTHONPATH:$PWD:$PWD/pricegenerator:$PWD/tests
      script:
        - echo "---> Running TESTING stage..."
        - pytest tests -v --disable-pytest-warnings
        - echo "---> Running BUILDING stage..."
        - python setup.py sdist bdist_wheel
        - |
          if [ $TRAVIS_PULL_REQUEST == false ]; then
            echo "---> Running PUBLISHING to PyPI stage...";
            python -m twine upload --verbose dist/* --skip-existing;
          else
            echo "---> SKIPPING PUBLISHING to PyPI stage, because this is Pull Request build";
          fi
      after_failure:
        - echo "Some issues occurred. See full logs."
      after_success:
        - |
          if [ $TRAVIS_PULL_REQUEST == false ]; then
            echo "All stages PRE-BUILDING -> TESTING -> BUILDING -> PUBLISHING to PyPI - done";
          else
            echo "All PR stages PRE-BUILDING -> TESTING -> BUILDING -> [PUBLISHING to PyPI][SKIPPED] - done";
          fi
